package com.ruoyi.web.controller.enterprise;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.AccountUserVO;
import com.ruoyi.system.domain.vo.SystemMenuVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GwPlatformRole;
import com.ruoyi.system.service.IGwPlatformRoleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 平台角色Controller
 * 
 * @author ruoyi
 * @date 2025-05-26
 */
@RestController
@RequestMapping("/system/platformRole")
public class GwPlatformRoleController extends BaseController
{
    @Autowired
    private IGwPlatformRoleService gwPlatformRoleService;

    /**
     * 查询平台角色列表
     */
//    @PreAuthorize("@ss.hasPermi('system:platformRole:list')")
    @GetMapping("/list")
    public TableDataInfo list(GwPlatformRole gwPlatformRole)
    {
        startPage();
        List<GwPlatformRole> list = gwPlatformRoleService.selectGwPlatformRoleList(gwPlatformRole);
        return getDataTable(list);
    }

   /**
    *获取角色列表（无分页）
    * @Date 下午 4:18:21 2025/5/29
    * @param gwPlatformRole
    * @return 结果
    **/
    @GetMapping("/platformRoleList")
    public AjaxResult platformRoleList(GwPlatformRole gwPlatformRole)
    {
        gwPlatformRole.setStatus("0");
        List<GwPlatformRole> list = gwPlatformRoleService.selectGwPlatformRoleList(gwPlatformRole);
        return AjaxResult.success(list);
    }

    /**
     * 导出平台角色列表
     */
//    @PreAuthorize("@ss.hasPermi('system:platformRole:export')")
    @Log(title = "平台角色", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GwPlatformRole gwPlatformRole)
    {
        List<GwPlatformRole> list = gwPlatformRoleService.selectGwPlatformRoleList(gwPlatformRole);
        ExcelUtil<GwPlatformRole> util = new ExcelUtil<GwPlatformRole>(GwPlatformRole.class);
        util.exportExcel(response, list, "平台角色数据");
    }

    /**
     * 获取平台角色详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:platformRole:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(gwPlatformRoleService.selectGwPlatformRoleById(id));
    }

    /**
     * 新增平台角色
     */
//    @PreAuthorize("@ss.hasPermi('system:platformRole:add')")
    @Log(title = "平台角色", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GwPlatformRole gwPlatformRole)
    {
        return toAjax(gwPlatformRoleService.insertGwPlatformRole(gwPlatformRole));
    }

    /**
     * 修改平台角色
     */
//    @PreAuthorize("@ss.hasPermi('system:platformRole:edit')")
    @Log(title = "平台角色", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GwPlatformRole gwPlatformRole)
    {
        return toAjax(gwPlatformRoleService.updateGwPlatformRole(gwPlatformRole));
    }

    /**
     * 删除平台角色
     */
//    @PreAuthorize("@ss.hasPermi('system:platformRole:remove')")
    @Log(title = "平台角色", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(gwPlatformRoleService.deleteGwPlatformRoleByIds(ids));
    }

    /**
     * 变更角色状态
     */
    @Log(title = "平台角色", businessType = BusinessType.INSERT)
    @PostMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody GwPlatformRole gwPlatformRole)
    {
        return gwPlatformRoleService.changeStatus(gwPlatformRole);
    }

    /**
     * 获取系统全部菜单
     */
    @Log(title = "平台角色", businessType = BusinessType.INSERT)
    @GetMapping("/getSystemAllMenu")
    public AjaxResult getSystemAllMenu()
    {
        List<SystemMenuVO> menuVOList = gwPlatformRoleService.getSystemAllMenu();
        return AjaxResult.success(menuVOList);
    }

    /**
     * 获取小程序全部菜单
     */
    @Log(title = "平台角色", businessType = BusinessType.INSERT)
    @GetMapping("/getAppletAllMenu")
    public AjaxResult getAppletAllMenu()
    {
        List<SystemMenuVO> menuVOList = gwPlatformRoleService.getAppletAllMenu();
        return AjaxResult.success(menuVOList);
    }

    /**
     * 根据角色ID查询关联用户
     * @Date 下午 3:06:07 2025/5/29
     * @param gwPlatformRole
     * @return 结果
     **/
    @Log(title = "平台角色", businessType = BusinessType.INSERT)
    @PostMapping("/getAccountByRole")
    public AjaxResult getAccountByRole(@RequestBody GwPlatformRole gwPlatformRole)
    {
        List<AccountUserVO> userList = gwPlatformRoleService.getAccountByRole(gwPlatformRole);
        return AjaxResult.success(userList);
    }

    /**
     * 移除角色关联用户
     * @Date 下午 3:21:34 2025/5/29
     * @param gwPlatformRole
     * @return 集合
     **/
    @Log(title = "平台角色", businessType = BusinessType.INSERT)
    @PostMapping("/deleteAccount")
    public AjaxResult deleteAccount(@RequestBody GwPlatformRole gwPlatformRole)
    {

        return toAjax(gwPlatformRoleService.deleteAccount(gwPlatformRole));
    }
}
